package com.yihuier.yihuier.Mapper.RoomManager;

import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface CompanyMapper {

    /**
     * 根据公司编号查询服务截止时间和公司名称
     * */
    @Select("SELECT company_deadline,company_name from bz_company WHERE company_id = #{company_id} AND company_status = 1;")
    Map<String,Object> selectRoomToCompanyTimeAndName(@Param("company_id") int company_id);

    @Select("SELECT company_deadline from bz_company WHERE company_id = #{company_id}")
    Date selectCompanyDeadline(@Param("company_id") int company_id);

    @Insert("INSERT into bz_company(company_name,company_deadline,advertisement_company) VALUES(#{company_name},#{company_deadline},#{advertisement_company})")
    int insertCompany(@Param("company_name") String company_name,@Param("company_deadline") String company_deadline,@Param("advertisement_company") int advertisement_company);

    @Select("SELECT company_id from bz_company WHERE company_name = #{company_name} AND company_deadline = #{company_deadline} AND advertisement_company = #{advertisement_company};")
    int selectCompanyIdWhenRegister(@Param("company_name") String company_name,@Param("company_deadline") String company_deadline,@Param("advertisement_company") int advertisement_company);

    @Select("SELECT company_name,company_deadline,company_status,advertisement_company from bz_company WHERE company_id = #{company_id};")
    Map<String,String> selectCompanyByCompanyId(@Param("company_id") Number company_id);

    @Select("SELECT company_id,company_name,company_deadline,company_status,advertisement_company from bz_company WHERE company_id != 1;")
    List<Map<String,Object>> selectAllCompany();

    @Update("UPDATE bz_company SET company_deadline = #{company_deadline} WHERE company_id = #{company_id}")
    int updateCompanyServerTime(@Param("company_id") String company_id,@Param("company_deadline") String company_deadline);


    @Select("SELECT IFNULL(MAX(department_belongs_company),0) FROM bz_department WHERE department_id = (SELECT department_id FROM bz_department_user WHERE user_id = #{user_id});")
    int selectCompanyIdOfUser(@Param("user_id")int user_id);

    @Update("UPDATE bz_company SET company_status = #{company_status} WHERE company_id = #{company_id}")
    int updateCompanyStatus(@Param("company_id") int company_id,@Param("company_status") int company_status);
}
